package com.easyidea.its.facade.tracklog.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.easyidea.its.domain.model.passport.TrackLog;
import com.easyidea.its.domain.model.system.Department;
import com.easyidea.its.domain.model.system.PassPort;
import com.easyidea.its.domain.service.department.DepartmentService;
import com.easyidea.its.domain.service.department.PassPortService;
import com.easyidea.its.domain.service.tracklog.TrackLogService;
import com.easyidea.its.facade.tracklog.TrackLogMgr;
import com.easyidea.its.util.StringUtil;
import com.easyidea.its.web.dto.CarSeizureDto;
import com.easyidea.its.web.dto.StatisticsDto;

public class TrackLogMgrImpl implements TrackLogMgr {
	private TrackLogService trackLogService;

	private DepartmentService departmentService;

	private PassPortService passPortService;

	public PassPortService getPassPortService() {
		return passPortService;
	}

	public void setPassPortService(PassPortService passPortService) {
		this.passPortService = passPortService;
	}

	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	public TrackLog getLatestTrackLogByCondition(String passPortName, String direction, boolean searchLeastRecord,
			Integer tracklogId, Date passTime) {
		passPortName = StringUtil.strDecode(passPortName);
		direction = StringUtil.strDecode(direction);
		TrackLog tracklog = trackLogService.getLatestTrackLogByCondition(passPortName, direction, searchLeastRecord,
				tracklogId, passTime);
		return tracklog;
	}

	public Integer getLatestTrackLogId(String passPortName, String direction, boolean searchLeastRecord) {
		TrackLog tracklog = this.getLatestTrackLogByCondition(passPortName, direction, searchLeastRecord, null, null);
		if (tracklog != null) {
			return tracklog.getId();
		}
		return null;
	}

	public TrackLogService getTrackLogService() {
		return trackLogService;
	}

	public void setTrackLogService(TrackLogService trackLogService) {
		this.trackLogService = trackLogService;
	}

	public Collection<Department> getAllDepartments() {
		// TODO Auto-generated method stub
		return departmentService.getAllDepartments();
	}

	public Collection<PassPort> getPassPortsByDeptId(Integer deptId) {
		return passPortService.getAllPassPortByDeptId(deptId);
	}

	public List<String> getDirectionsByPassPortName(String passPortName) {
		PassPort pp = passPortService.getPassPortByPassPortName(passPortName);
		if (pp != null) {
			List<String> directions = new ArrayList<String>();
			directions.add(pp.getStartpoint());
			directions.add(pp.getEndpoint());
			return directions;
		}
		return null;

	}

	public List<TrackLog> getTrackLogsByCondition(CarSeizureDto carSeizureDto, int startIndex, int pageSize) {
		// TODO Auto-generated method stub
		return trackLogService.getTrackLogsByCondition(carSeizureDto, startIndex, pageSize);
	}

	public int getTrackLogsCountByCondition(CarSeizureDto carSeizureDto) {
		// TODO Auto-generated method stub
		return trackLogService.getTrackLogsCountByCondition(carSeizureDto);
	}

	public Collection<PassPort> getAllPassPorts() {
		return passPortService.getAllPassPorts();
	}

	public boolean modifyPlatNumber(Integer id, String plateNumber) {
		return trackLogService.modifyPlatNumber(id, plateNumber);
	}

	public Collection<Object[]> statisticsByCondition(StatisticsDto statisticsDto) {
		return this.trackLogService.statisticsByCondition(statisticsDto);
	}
}
